<!DOCTYPE html>
<html lang="zh-hans">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.3.0">


  <link rel="apple-touch-icon" sizes="180x180" href="/wow/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/wow/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/wow/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/wow/images/logo.svg" color="#222">

<link rel="stylesheet" href="/wow/css/main.css">



<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.15.3/css/all.min.css">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/animate.css@3.1.1/animate.min.css">

<script class="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"single-flower.gitee.io","root":"/wow/","images":"/wow/images","scheme":"Muse","version":"8.3.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":false,"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"بحث...","empty":"We didn't find any results for the search: ${query}","hits_time":"${hits} results found in ${time} ms","hits":"${hits} results found"}};
  </script>
<meta name="description" content="什么是dockerDocker 是一个开源的应用容器引擎，让开发者可以打包他们的应用以及依赖包到一个可移植的镜像中，然后发布到任何流行的 Linux或Windows 机器上，也可以实现虚拟化。容器是完全使用沙箱机制，相互之间不会有任何接口 docker-优点快速部署：短时间内可以部署成百上千个应⽤，更快速交付到线上⾼效虚拟化：不需要额外hypervisor⽀持，基于linux内核实现应⽤虚拟化，相">
<meta property="og:type" content="article">
<meta property="og:title" content="docker操作容器，镜像">
<meta property="og:url" content="https://single-flower.gitee.io/wow/2021/02/18/zy/docker%E6%93%8D%E4%BD%9C%E5%AE%B9%E5%99%A8%EF%BC%8C%E9%95%9C%E5%83%8F/index.html">
<meta property="og:site_name" content="朵朵最可爱">
<meta property="og:description" content="什么是dockerDocker 是一个开源的应用容器引擎，让开发者可以打包他们的应用以及依赖包到一个可移植的镜像中，然后发布到任何流行的 Linux或Windows 机器上，也可以实现虚拟化。容器是完全使用沙箱机制，相互之间不会有任何接口 docker-优点快速部署：短时间内可以部署成百上千个应⽤，更快速交付到线上⾼效虚拟化：不需要额外hypervisor⽀持，基于linux内核实现应⽤虚拟化，相">
<meta property="og:locale">
<meta property="article:published_time" content="2021-02-18T10:53:19.526Z">
<meta property="article:modified_time" content="2021-04-13T07:05:37.673Z">
<meta property="article:author" content="X y">
<meta property="article:tag" content="-GIT">
<meta name="twitter:card" content="summary">


<link rel="canonical" href="https://single-flower.gitee.io/wow/2021/02/18/zy/docker%E6%93%8D%E4%BD%9C%E5%AE%B9%E5%99%A8%EF%BC%8C%E9%95%9C%E5%83%8F/">


<script class="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-hans'
  };
</script>
<title>docker操作容器，镜像 | 朵朵最可爱</title>
  




  <noscript>
  <style>
  body { margin-top: 2rem; }

  .use-motion .menu-item,
  .use-motion .sidebar,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header {
    visibility: visible;
  }

  .use-motion .header,
  .use-motion .site-brand-container .toggle,
  .use-motion .footer { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle,
  .use-motion .custom-logo-image {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line {
    transform: scaleX(1);
  }

  .search-pop-overlay, .sidebar-nav { display: none; }
  .sidebar-panel { display: block; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="تشغيل شريط التصفح" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/wow/" class="brand" rel="start">
      <i class="logo-line"></i>
      <h1 class="site-title">朵朵最可爱</h1>
      <i class="logo-line"></i>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu">
        <li class="menu-item menu-item-home"><a href="/wow/" rel="section"><i class="fa fa-home fa-fw"></i>Home</a></li>
        <li class="menu-item menu-item-about"><a href="/wow/about/" rel="section"><i class="fa fa-user fa-fw"></i>معلومات</a></li>
        <li class="menu-item menu-item-tags"><a href="/wow/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>الوسوم</a></li>
        <li class="menu-item menu-item-categories"><a href="/wow/categories/" rel="section"><i class="fa fa-th fa-fw"></i>التصنيفات</a></li>
        <li class="menu-item menu-item-archives"><a href="/wow/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>الأرشيفات</a></li>
  </ul>
</nav>




</div>
        
  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>

  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          المحتويات
        </li>
        <li class="sidebar-nav-overview">
          عام
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%BB%80%E4%B9%88%E6%98%AFdocker"><span class="nav-number">1.</span> <span class="nav-text">什么是docker</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#docker-%E4%BC%98%E7%82%B9"><span class="nav-number">2.</span> <span class="nav-text">docker-优点</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#docker-%E4%B8%89%E4%B8%AA%E5%9F%BA%E6%9C%AC%E6%A6%82%E5%BF%B5"><span class="nav-number">3.</span> <span class="nav-text">docker-三个基本概念</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#Image-%E9%95%9C%E5%83%8F"><span class="nav-number">3.1.</span> <span class="nav-text">Image(镜像)</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Container-%E5%AE%B9%E5%99%A8"><span class="nav-number">3.2.</span> <span class="nav-text">Container(容器)</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Repository-%E4%BB%93%E5%BA%93"><span class="nav-number">3.3.</span> <span class="nav-text">Repository(仓库)</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#docker-%E9%95%9C%E5%83%8F"><span class="nav-number">4.</span> <span class="nav-text">docker-镜像</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4"><span class="nav-number">4.1.</span> <span class="nav-text">常用命令</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%93%8D%E4%BD%9C-%E5%91%BD%E4%BB%A4"><span class="nav-number">5.</span> <span class="nav-text">操作        命令</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%A3%80%E6%B5%8B%E4%BA%91%E7%AB%AF%E9%95%9C%E5%83%8F"><span class="nav-number">5.1.</span> <span class="nav-text">检测云端镜像</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E4%B8%8B%E8%BD%BD%E9%95%9C%E5%83%8F"><span class="nav-number">5.2.</span> <span class="nav-text">下载镜像</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%9F%A5%E7%9C%8B%E6%9C%AC%E5%9C%B0%E9%95%9C%E5%83%8F"><span class="nav-number">5.3.</span> <span class="nav-text">查看本地镜像</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%88%A0%E9%99%A4%E9%95%9C%E5%83%8F"><span class="nav-number">5.4.</span> <span class="nav-text">删除镜像</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#docker-%E5%AE%B9%E5%99%A8"><span class="nav-number">6.</span> <span class="nav-text">docker-容器</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4-1"><span class="nav-number">6.1.</span> <span class="nav-text">常用命令</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%93%8D%E4%BD%9C-%E5%91%BD%E4%BB%A4-1"><span class="nav-number">7.</span> <span class="nav-text">操作        命令</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C"><span class="nav-number">8.</span> <span class="nav-text">常用操作</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%9F%A5%E7%9C%8B%E5%AE%B9%E5%99%A8"><span class="nav-number">8.1.</span> <span class="nav-text">查看容器</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%BF%90%E8%A1%8C%E5%AE%B9%E5%99%A8"><span class="nav-number">8.2.</span> <span class="nav-text">运行容器</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%81%9C%E6%AD%A2%E5%AE%B9%E5%99%A8"><span class="nav-number">8.3.</span> <span class="nav-text">停止容器</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%90%AF%E5%8A%A8%E5%AE%B9%E5%99%A8"><span class="nav-number">8.4.</span> <span class="nav-text">启动容器</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%88%A0%E9%99%A4%E5%AE%B9%E5%99%A8"><span class="nav-number">8.5.</span> <span class="nav-text">删除容器</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%9F%A5%E7%9C%8B%E5%AE%B9%E5%99%A8%E6%97%A5%E5%BF%97"><span class="nav-number">8.6.</span> <span class="nav-text">查看容器日志</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%BB%80%E4%B9%88%E6%98%AFdockerfile"><span class="nav-number">9.</span> <span class="nav-text">什么是dockerfile</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#dockerfile%E5%9F%BA%E6%9C%AC%E7%BB%93%E6%9E%84"><span class="nav-number">10.</span> <span class="nav-text">dockerfile基本结构</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#dockerfile%E5%B8%B8%E7%94%A8%E6%8C%87%E4%BB%A4"><span class="nav-number">11.</span> <span class="nav-text">dockerfile常用指令</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#FROM"><span class="nav-number">11.1.</span> <span class="nav-text">FROM</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#LABEL"><span class="nav-number">11.2.</span> <span class="nav-text">LABEL</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#RUN"><span class="nav-number">11.3.</span> <span class="nav-text">RUN</span></a></li></ol></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">X y</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap site-overview-item animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/wow/archives/">
        
          <span class="site-state-item-count">23</span>
          <span class="site-state-item-name">المقالات</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
        <span class="site-state-item-count">1</span>
        <span class="site-state-item-name">التصنيفات</span>
      </div>
      <div class="site-state-item site-state-tags">
        <span class="site-state-item-count">1</span>
        <span class="site-state-item-name">الوسوم</span>
      </div>
  </nav>
</div>



        </div>
      </div>
    </div>
  </aside>
  <div class="sidebar-dimmer"></div>


    </header>

    
  <div class="back-to-top" role="button" aria-label="Back to top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-hans">
    <link itemprop="mainEntityOfPage" href="https://single-flower.gitee.io/wow/2021/02/18/zy/docker%E6%93%8D%E4%BD%9C%E5%AE%B9%E5%99%A8%EF%BC%8C%E9%95%9C%E5%83%8F/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/wow/images/avatar.gif">
      <meta itemprop="name" content="X y">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="朵朵最可爱">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          docker操作容器，镜像
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">نُشر في</span>

      <time title="أُنشأ: 2021-02-18 18:53:19" itemprop="dateCreated datePublished" datetime="2021-02-18T18:53:19+08:00">2021-02-18</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">عُدل في</span>
        <time title="عُدل: 2021-04-13 15:05:37" itemprop="dateModified" datetime="2021-04-13T15:05:37+08:00">2021-04-13</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">في</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/wow/categories/GIT/" itemprop="url" rel="index"><span itemprop="name">-GIT</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
        <h2 id="什么是docker"><a href="#什么是docker" class="headerlink" title="什么是docker"></a>什么是docker</h2><p>Docker 是一个开源的应用容器引擎，让开发者可以打包他们的应用以及依赖包到一个可移植的镜像中，然后发布到任何流行的 Linux或Windows 机器上，也可以实现虚拟化。容器是完全使用沙箱机制，相互之间不会有任何接口</p>
<h2 id="docker-优点"><a href="#docker-优点" class="headerlink" title="docker-优点"></a>docker-优点</h2><p>快速部署：短时间内可以部署成百上千个应⽤，更快速交付到线上<br>⾼效虚拟化：不需要额外hypervisor⽀持，基于linux内核实现应⽤虚拟化，相⽐虚拟机⼤幅提⾼<br>性能和效率<br>节省开⽀：提⾼服务器利⽤率，降低IT⽀出<br>简化配置：将运⾏环境打包保存⾄容器，使⽤时直接启动即可<br>环境统⼀：将开发，测试，⽣产的应⽤运⾏环境进⾏标准化和统⼀，减少环境不⼀样带来的各种问<br>题<br>快速迁移和扩展：可实现跨平台运⾏在物理机、虚拟机、公有云等环境，良好的兼容性可以⽅便将<br>应⽤从A宿主机迁移到B宿主机，甚⾄是A平台迁移到B平台</p>
<h2 id="docker-三个基本概念"><a href="#docker-三个基本概念" class="headerlink" title="docker-三个基本概念"></a>docker-三个基本概念</h2><h3 id="Image-镜像"><a href="#Image-镜像" class="headerlink" title="Image(镜像)"></a>Image(镜像)</h3><p>Docker 镜像就是一个只读的模板，镜像可以用来创建 Docker 容器。Docker 提供了一个很简单的机制来创建镜像或者更新现有的镜像，用户甚至可以直接从其他人那里下载一个已经做好的镜像来直接使用。镜像是一种文件结构。Dockerfile中的每条命令都会在文件系统中创建一个新的层次结构，文件系统在这些层次上构建起来，镜像就构建于这些联合的文件系统之上。Docker官方网站专门有一个页面来存储所有可用的镜像，网址是：index.docker.io</p>
<h3 id="Container-容器"><a href="#Container-容器" class="headerlink" title="Container(容器)"></a>Container(容器)</h3><p>容器是从镜像创建的运行实例。它可以被启动、开始、停止、删除。每个容器都是相互隔离的、保证安全的平台。可以把容器看做是一个简易版的 Linux 环境，Docker 利用容器来运行应用</p>
<h3 id="Repository-仓库"><a href="#Repository-仓库" class="headerlink" title="Repository(仓库)"></a>Repository(仓库)</h3><p>public(公有仓库) private(私有仓库)<br>仓库是集中存放镜像文件的场所，仓库注册服务器（Registry）上往往存放着多个仓库，每个仓库中又包含了多个镜像，每个镜像有不同的标签（tag）。目前，最大的公开仓库是 Docker Hub，存放了数量庞大的镜像供用户下载</p>
<h2 id="docker-镜像"><a href="#docker-镜像" class="headerlink" title="docker-镜像"></a>docker-镜像</h2><h3 id="常用命令"><a href="#常用命令" class="headerlink" title="常用命令"></a>常用命令</h3><h2 id="操作-命令"><a href="#操作-命令" class="headerlink" title="操作        命令"></a>操作        命令</h2><p>搜索镜像    docker search [OPTIONS] 镜像名称<br>上传镜像    docker push [OPTIONS] NAME[:TAG]<br>下载镜像    docker pull [OPTIONS] NAME[:TAG]<br>提交镜像    docker commit [OPTIONS] CONTAINER NAME[:TAG]<br>构建镜像    docker build [OPTIONS] PATH<br>增加镜像标签    docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]<br>查看本地所有镜像    docker images [OPTIONS] [REPOSITORY[:TAG]]<br>删除指定的本地镜像    docker rmi [OPTIONS] IMAGE [IMAGE…]</p>
<p>常用操作</p>
<h3 id="检测云端镜像"><a href="#检测云端镜像" class="headerlink" title="检测云端镜像"></a>检测云端镜像</h3><p>docker search 关键字<br>如检索 “ mysql “：[root@localhost ~]# docker search mysql</p>
<h3 id="下载镜像"><a href="#下载镜像" class="headerlink" title="下载镜像"></a>下载镜像</h3><p>docker pull 镜像名称:tag<br>“ :tag ” 不写时默认下载最新版本的镜像，也可以自己指定 tag 从而下载指定版本的镜像，tag 名称可以从 Docker Hub 上自己查看</p>
<h3 id="查看本地镜像"><a href="#查看本地镜像" class="headerlink" title="查看本地镜像"></a>查看本地镜像</h3><p>docker images</p>
<h3 id="删除镜像"><a href="#删除镜像" class="headerlink" title="删除镜像"></a>删除镜像</h3><p>docker rmi image-id</p>
<h2 id="docker-容器"><a href="#docker-容器" class="headerlink" title="docker-容器"></a>docker-容器</h2><p>软件镜像(Images)启动之后就会有一个对应的容器(Container)，镜像位于自己的容器中，容器之间相互隔离</p>
<h3 id="常用命令-1"><a href="#常用命令-1" class="headerlink" title="常用命令"></a>常用命令</h3><h2 id="操作-命令-1"><a href="#操作-命令-1" class="headerlink" title="操作        命令"></a>操作        命令</h2><p>运行容器    docker run –name container-name -d image-name:tag<br>启动容器    docker start container-name/container-id<br>重启容器    docker restart container-name/container-id<br>查看容器列表    docker ps [option]<br>停止容器    docker stop container-name/container-id<br>删除容器    docker rm container-id<br>重命名容器    docker rename CONTAINER CONTAINER_NEW<br>进入容器    docker attach CONTAINER<br>执行容器命令    docker exec CONTAINER COMMAND<br>端口映射    docker run –name myredis -d -p 6379:6379 docker.io/redis<br>查看容器日志    docker logs container-name/container-id</p>
<h2 id="常用操作"><a href="#常用操作" class="headerlink" title="常用操作"></a>常用操作</h2><h3 id="查看容器"><a href="#查看容器" class="headerlink" title="查看容器"></a>查看容器</h3><p>docker ps<br>加上 -a 参数可以查看所有容器</p>
<h3 id="运行容器"><a href="#运行容器" class="headerlink" title="运行容器"></a>运行容器</h3><p>docker run –name container-name:tag -d image-name<br>–name：自定义容器名，不指定时，docker 会自动生成一个名称<br>-d：表示后台运行容器<br>image-name：指定运行的镜像名称以及 Tag</p>
<h3 id="停止容器"><a href="#停止容器" class="headerlink" title="停止容器"></a>停止容器</h3><p>docker stop container-name|container-id<br>指定容器名或者容器 id 即可</p>
<h3 id="启动容器"><a href="#启动容器" class="headerlink" title="启动容器"></a>启动容器</h3><p>docker start container-name|container-id<br>指定容器名或者容器 id 即可</p>
<h3 id="删除容器"><a href="#删除容器" class="headerlink" title="删除容器"></a>删除容器</h3><p>docker rm container-id<br>根据 容器 id 进行删除容器，删除前必须先停止容器</p>
<h3 id="查看容器日志"><a href="#查看容器日志" class="headerlink" title="查看容器日志"></a>查看容器日志</h3><p>docker logs container-name|container-id<br>指定容器名或者容器 id 即可</p>
<h2 id="什么是dockerfile"><a href="#什么是dockerfile" class="headerlink" title="什么是dockerfile"></a>什么是dockerfile</h2><p>Dockerfile 是自动构建 docker 镜像的配置文件， 用户可以使用 Dockerfile 快速创建自定义的镜像。Dockerfile 中的命令非常类似于 linux 下的 shell 命令<br>Dockerfile 可以自定义镜像，通过 Docker 命令去运行镜像，从而达到启动容器的目的</p>
<h2 id="dockerfile基本结构"><a href="#dockerfile基本结构" class="headerlink" title="dockerfile基本结构"></a>dockerfile基本结构</h2><p>基础镜像(父镜像)信息指令 FROM<br>维护者信息指令 MAINTAINER<br>镜像操作指令 RUN 、 EVN 、 ADD 和 WORKDIR 等<br>容器启动指令 CMD 、 ENTRYPOINT 和 USER 等</p>
<h2 id="dockerfile常用指令"><a href="#dockerfile常用指令" class="headerlink" title="dockerfile常用指令"></a>dockerfile常用指令</h2><p>Dockerfile 的指令每执⾏⼀次都会在 docker 上新建⼀层。所以过多⽆意义的层，会造成镜像膨胀 过⼤</p>
<h3 id="FROM"><a href="#FROM" class="headerlink" title="FROM"></a>FROM</h3><p>定制镜像，需要先有⼀个基础镜像，在这个基础镜像上进⾏定制。FROM 就是指定基础镜像，此<br>指令必需放在有效指令的第⼀⾏</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">FROM nginx</span><br><span class="line">RUN echo <span class="string">&#x27;这是⼀个本地构建的nginx镜像&#x27;</span> &gt; <span class="regexp">/usr/</span>share/nginx/html/index.html</span><br></pre></td></tr></table></figure>
<h3 id="LABEL"><a href="#LABEL" class="headerlink" title="LABEL"></a>LABEL</h3><p>可以指定镜像元数据，如：镜像作者等</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">LABEL &lt;key&gt;=&lt;value&gt; &lt;key&gt;=&lt;value&gt; ...</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">LABEL version=<span class="string">&quot;1.0&quot;</span></span><br><span class="line">LABEL description=<span class="string">&#x27;this is a content&#x27;</span></span><br></pre></td></tr></table></figure>
<h3 id="RUN"><a href="#RUN" class="headerlink" title="RUN"></a>RUN</h3><p>⽤来执⾏命令、RUN 指令经常⽤来调⽤shell指令<br>注意：run可以写多个，每⼀个run指令都会建⽴⼀层，所以尽可能合并成⼀条指令</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">RUN &lt;命令&gt;</span><br><span class="line">RUN [<span class="string">&quot;可执⾏⽂件&quot;</span>,<span class="string">&quot;参数1&quot;</span>,<span class="string">&quot;参数2&quot;</span>]</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">RUN echo <span class="string">&quot;hello world&quot;</span> &gt; <span class="regexp">/usr/</span>share/nginx/html/index.html</span><br><span class="line">RUN yum install epel-release \</span><br><span class="line"> &amp;&amp; yum install nginx \</span><br><span class="line"> &amp;&amp; yum install mysql</span><br><span class="line"></span><br><span class="line">k</span><br><span class="line">RUN [<span class="string">&quot;/usr/bin/python3&quot;</span>,<span class="string">&quot;1.py&quot;</span>]</span><br></pre></td></tr></table></figure>
    </div>

    
    
    

    <footer class="post-footer">
          <div class="post-tags">
              <a href="/wow/tags/GIT/" rel="tag"># -GIT</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/wow/2021/02/18/zy/%E8%A7%86%E9%A2%91%E7%9B%B4%E6%92%AD/" rel="prev" title="视频直播">
                  <i class="fa fa-chevron-left"></i> 视频直播
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/wow/2021/04/06/SD/%E9%9D%A2%E8%AF%95%E9%A2%98_%E8%AF%AD%E8%A8%80%E7%9B%B8%E5%85%B31/" rel="next" title="语言相关1">
                  语言相关1 <i class="fa fa-chevron-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>







<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      const activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      const commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>
</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">


<div class="copyright">
  &copy; 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">X y</span>
</div>
  <div class="powered-by">تطبيق الموقع <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/muse/" class="theme-link" rel="noopener" target="_blank">NexT.Muse</a>
  </div>

    </div>
  </footer>

  
  <script src="https://cdn.jsdelivr.net/npm/animejs@3.2.1/lib/anime.min.js"></script>
<script src="/wow/js/utils.js"></script><script src="/wow/js/motion.js"></script><script src="/wow/js/schemes/muse.js"></script><script src="/wow/js/next-boot.js"></script>

  






  





</body>
</html>
